define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dormitory/building/index',
                    add_url: 'dormitory/building/add',
                    edit_url: 'dormitory/building/edit',
                    del_url: 'dormitory/building/del',
                    multi_url: 'dormitory/building/multi',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'building.id',
                commonSearch: true,
                searchFormVisible: true,
                columns: [
                    [

                        {field: 'state', checkbox: true, },
                        //通过Ajax渲染searchList，也可以使用JSON数据
                        // {
                        //     field: 'garden_number',
                        //     title: __('Garden'),
                        //     align: 'left',
                        //     searchList: $.getJSON('dormitory/garden/searchlist?search=a&field=row[garden_number]'),
                        //     visible: false
                        // },

                        {field: 'school_name', title: __('学校'), operate: false},
                        {field: 'garden_name', title: __('Garden Name'), operate: false},
                        {field: 'floor', title: __('Floor'), operate: false},
                        {field: 'floor_room_count', title: __('Floor Dorm Count'), operate: false},
                        {field: 'number', title: __('Number'), operate: false},
                        {field: 'name', title: __('Name'), operate: false},
                        {field: 'dorm_bed_count', title: __('Dorm Bed Count'), operate: false},
                        {field: 'dorm_price', title: __('Dorm Price'), operate: false},
                        {field: 'dorm_type_text', title: __('Dorm Type'), operate: false},
                        {field: 'building.number', title: __('Number'), visible: false},
                        {field: 'building.name', title: __('Name'), visible: false},
                        /*{
                            field: 'dorm_type',
                            title: __('Dorm Type'),
                            align: 'left',
                            searchList: $.getJSON('dormitory/dorm/typeList?search=a&field=row[dorm_type]'),
                            visible: false
                        },*/

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $(document).on('click', ".btn-embossed", function () {
                    $('#init_dorm').val(0);
                });
                $(document).on('click', ".btn-init", function () {
                    $('#init_dorm').val(1);
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});